﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SceneManager
{
    public class SkySphere : DrawableObject
    {
        ComplexModel model;
        Effect effect;

        public SkySphere(Game game) : base(game)
        {
            TextureCube texture = Game.Content.Load<TextureCube>("SkySphere");

            model = new ComplexModel(Game, "Models/Sphere", Vector3.Zero, Vector3.Zero, -new Vector3(10000), new Material("Montagnes", 0, 0));

            effect = Game.Content.Load<Effect>("Shaders/SkySphere");
            effect.Parameters["CubeMap"].SetValue(texture);
        }

        public override void Draw(Camera camera, GameTime gameTime)
        {
            Game.GraphicsDevice.DepthStencilState = DepthStencilState.None;

            model.Position = camera.Position;
            model.Effect = Effect;
            if (Effect.Parameters.Count(p => p.Name == "InfiniteDepth") == 1)
                Effect.Parameters["InfiniteDepth"].SetValue(true);
            model.Draw(camera, gameTime);
            if (Effect.Parameters.Count(p => p.Name == "InfiniteDepth") == 1)
                Effect.Parameters["InfiniteDepth"].SetValue(false);

            Game.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
        }
    }
}
